﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VietPremier.Areas.AdminCP.Models;

namespace VietPremier.Areas.AdminCP.Controllers
{
    public class AdminAboutUsController : Controller
    {
       

        #region "Index"
        public ActionResult Index()
        {
            using (dbVietPremierDataContext db = new dbVietPremierDataContext())
            {
                var query = db.EntityAboutUs.Select(p => new AdminAboutUsModel { Id = p.Id, Name = p.Name, Body = p.Body, Meta_keyword = p.Meta_keyword, Meta_description = p.Meta_description, Titletag = p.Titletag }).FirstOrDefault();
                if (query != null)
                    return View(query);
                else
                    return View("Error");
            }
           
        }
        #endregion

        #region "Edit"
        public ActionResult Edit(int id)
        {
            using (dbVietPremierDataContext db = new dbVietPremierDataContext())
            {
                var query = db.EntityAboutUs.Where(p => p.Id == id).Select(p => new AdminAboutUsModel { Id = p.Id, Name = p.Name, Body = p.Body, Meta_keyword = p.Meta_keyword, Meta_description = p.Meta_description, Titletag = p.Titletag }).FirstOrDefault();
                if (query != null)
                    return View(query);
                else
                    return View("Error");
            }
        }
        [ValidateInput(false)]
        [HttpPost]
        public ActionResult Edit(int Id, string Name, string Body, string Titletag, string Meta_description, string Meta_keyword)
        {
            using (dbVietPremierDataContext db = new dbVietPremierDataContext())
            {
                var query = db.EntityAboutUs.FirstOrDefault(p => p.Id == Id);
                if (query != null)
                {
                    query.Name = Name;
                    query.Body = Body;
                    query.Titletag = Titletag;
                    query.Meta_description = Meta_description;
                    query.Meta_keyword = Meta_keyword;
                    db.SubmitChanges();
                    return RedirectToAction("Index", "AdminAboutUs");
                }
                else
                    return View("Error");
            }
        }
        #endregion
    }
}
